# -*- coding = utf-8 -*-
# @Time: 2021/11/22 20:47
# @Author : Saki;
# @File : search_indexes.py
# @Software : PyCharm
from haystack import indexes
from search.models import Papers


class PapersIndex(indexes.SearchIndex,indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    publish = indexes.CharField(model_attr='publish')
    authors = indexes.CharField(model_attr='authors')
    keywords = indexes.CharField(model_attr='keywords')
    abstract = indexes.CharField(model_attr='abstract')
    link = indexes.CharField(model_attr='link')
    ref_wf = indexes.CharField(model_attr='ref_wf')
    publish_year = indexes.CharField(model_attr='publish_year')

    def get_model(self):
        """
        返回建立索引的模型
        :return:
        """
        return Papers

    def index_queryset(self, using=None):
        """
        返回要建立索引的数据查询集
        :param using:
        :return:
        """
        # 这种写法遵从官方文档的指引
        return self.get_model().objects.all()



